#ifndef SERVER_H_
#define SERVER_H_

#include "Thread.h"
#include "NetworkWrapper.h"
#include "ServerMessageReceiver.h"
#include <map>
#include <tr1/memory>

class Server : public Thread
{
public:
    Server();
    virtual ~Server();
    void sendToClients(NetworkEvent& event);
    void sendToClient(NetworkEvent& event, long playerId);
    void sendToClients(NetworkEvents& events);
    void removeClient(int id);
    unsigned int getNrOfPlayers();

protected:
    virtual void mainLoop();
    virtual void init();
    virtual void cleanUp();

private:
    TCPsocket serverSocket;
    typedef std::map<int, ServerMessageReceiverPtr> ServerMessageReceiverMap;
    ServerMessageReceiverMap messageReceivers;
    int currentId;
};

typedef std::tr1::shared_ptr<Server> ServerPtr;

#endif
